<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$pindex = max(1, intval($_SESSION['page']));
	$psize = 15;
	$return['post']= '';
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);	
    //$fields=array('id','ordersn','name','mobile','driver_id','mid','createtime','status','price','price1','start_seat','dest_seat','cuid');
    $orderby='createtime desc';
	$total='';
	$return['list']=pdo_getslice('jy_smallquan_manager_order',$params,array($pindex,$psize),$total,$fields,'',$orderby);	
	$hid=pdo_getcolumn('jy_smallquan_household',array('mid'=>$_SESSION['uid']),'hid');
	$bid=pdo_getcolumn('jy_smallquan_house',array('id'=>$hid),'bid');
	$building=pdo_get('jy_smallquan_building',array('id'=>$bid));
	$return['title']=$building['area'].$building['qishu'].$building['dongshu'].'栋';
	$return['managermobile']=pdo_getcolumn('jy_smallquan_manager',array('bid'=>$bid),'mobile');
	$return['avatar']=pdo_getcolumn('core_members',array('id'=>$_SESSION['uid']),'avatar');
	if($return['list']){
		foreach($return['list'] as &$v){
			$member=pdo_get('core_members',array('id'=>$v['managerid']),array('mobile','realname'));
			$v['realname']=$member['realname'];
			$v['mobile']=$member['mobile'];
			$v['createtime']=date('Y-m-d H:i:s',$v['createtime']);
		}
	}
	$return['type']=array('1'=>'拍照','2'=>'送水','3'=>'维修','4'=>'帮忙');
	$return['status']=array('0'=>'待服务','1'=>'正在处理','2'=>'已完成');
	$return['post']=array();
	exi($return);
}
if($_RQ['op']=='list'){
	
	$return['type']=array('1'=>'拍照','2'=>'送水','3'=>'维修','4'=>'帮忙');
	$return['status']=array('0'=>'待服务','1'=>'正在处理','2'=>'已完成');
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);	
    $orderby='createtime asc';
	$total='';
	$list=pdo_getslice('jy_smallquan_manager_order',$params,array($pindex,$psize),$total,$fields,'',$orderby);	
	$html = '';
	
	
	if($list){
		foreach($list as &$v){
			$member=pdo_get('core_members',array('id'=>$v['managerid']),array('mobile','realname'));
			$v['managername']=$member['realname'];
			$v['managerstatus']=$return['status'][$v['status']].'任务';
			$v['mobile']=$member['mobile'];
			$v['images']=json_decode($v['images'],true);
			$v['createtime']=date('Y-m-d H:i:s',$v['createtime']);
			
			$htmltime = '<div class="logtime">'.$v['createtime'].'</div>';
			$html .= $htmltime;
			if($v['mid'] == $_SESSION['uid']){
				$v['subtitle']=$v['type']==2?'有空桶':'';
				if($v['images']){
					
					$v['image']=tomedia($v['images']['0']);
					
				}
				$html .='<div class="r clearfix"><img class="pic"/><p class="text"><span class="bold" style="color:#6633FF;margin-right:0.2rem">'.$return['type'][$v['type']].'</span><span class="subtitle">'.$v['subtitle'].'</span></br>'.$v['content'].'</p></div>';
				
				if($_SESSION['os']=='wxapp'){
					$v['subtitle']=$v['type']==2?'有空桶':'';
					$v['content']= $v['content'];
				}
			}else{
				$v['msg']='【'.$return['type'][$v['type']].'-状态已更新】'.$v['managername'].$v['managerstatus'].' <a class="bold" href="./index.php?plugin=jy_water&action=order_detail&id='.$v['id'].'" style="color:#003399">立即查看</a>';
				$html .='<div class="l clearfix"><image class="pic"/><p class="text">'.$v['msg'].'</p></div>';
				if($_SESSION['os']=='wxapp'){
					$v['msg']='【'.$return['type'][$v['type']].'-状态已更新】'.$v['managername'].$v['managerstatus'];
					$v['url']= './index.php?plugin=jy_water&action=order_detail&id='.$v['id'];
				}
			}
		}
	}
	
	$return['list']= $list;
	$return['html']= $html;
	exi($return);
}
if($_RQ['op']=='orderubmit'){
	$post=get_postdata();
	$post['fuwutime']=str_replace('T','/',$post['fuwutime']);
	$household=pdo_get('jy_smallquan_household',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid'],'status'=>1));
	if(empty($household)){
			exi('您还不是业主！','','jy_smallquan/area/');
	}
	$type=intval($post['type']);
	$updata=array(
		'mid'=>$_SESSION['uid'],
		'type'=>$type,
		'content'=>$post['content'],
		'fuwutime'=>$post['fuwutime'],
		'images'=>ijson_encode($post['images']),
		'uniacid'=>$_SESSION['uniacid'],
		'createtime'=>time()
	);
	pdo_insert('jy_smallquan_manager_order',$updata);
	exi('提交成功','','/index/');
}
